package com.iwhalecloud.bss.kite.cucc.web.controller.attr;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.IBankBranchService;
import com.iwhalecloud.bss.kite.cucc.client.dto.attr.BankBranch;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName : BankBranchController
 * @Description : 银行
 * @Author : chen.cheng110
 * @Date : 2020/12/08 15:00
 */
@Api(tags = {"/bankBranch - 银行"})
@RestController
@RequestMapping("/bankBranch")
public class BankBranchController {
    @Resource
    private IBankBranchService bankBranchService;

    @ApiOperation(value = "搜索所属银行", notes = "搜索所属银行")
    @ApiImplicitParams({@ApiImplicitParam(name = "bankCode", value = "上级银行编码")})
    @GetMapping("/superBankName")
    public DataResult<List<BankBranch>> superBankName(@RequestParam(required = false) String bankCode) {
        // 根据银行编码返回所属银行
        List<BankBranch> bankNames = bankBranchService.listSuperBankName(bankCode);
        return ErrorConsts.SUCCESS.getResult(bankNames);
    }

    @ApiOperation(value = "可选所有下属银行", notes = "可选所有下属银行")
    @ApiImplicitParams({@ApiImplicitParam(name = "bankCode", value = "父类银行编码")})
    @GetMapping("/subBankName")
    public DataResult<List<BankBranch>> subBankName(@RequestParam(required = false) String bankCode) {
        //根据父类银行编码 查询可选的所有子银行(开户银行)
        List<BankBranch> bankNames = bankBranchService.listSubBankName(bankCode);
        return ErrorConsts.SUCCESS.getResult(bankNames);
    }

    @ApiOperation(value = "搜索可选下属银行", notes = "搜索可选下属银行")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "subBankName", value = "模糊搜索银行名称")
    })
    @GetMapping("/qrySubBankName")
    public DataResult<List<BankBranch>> qrySubBankName(@RequestParam(required = false) String subBankName) {
        // 根据可选所有子银行(开户银行) 按"名称"模糊搜索
        List<BankBranch> bankNames = bankBranchService.qryListSubBankName(subBankName);
        return ErrorConsts.SUCCESS.getResult(bankNames);
    }
}
